package gclib;

import gclib.inventory.Armor;
import gclib.inventory.Shield;
import gclib.inventory.Weapon;
import gclib.inventory.Item;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Jason
 */
public class Equipment {

    public static enum EQUIP_SLOTS {ARMOR, HEAD, NECK, ARMS, HANDS, RING_LEFT, RING_RIGHT, WAIST, FEET};
    private Map<EQUIP_SLOTS, Armor> equipted = new EnumMap<EQUIP_SLOTS, Armor>(EQUIP_SLOTS.class);
    private Weapon equiptedWeapon;
    private Character character;
    private List<Item> items = new ArrayList<Item>();//Collections.emptyList();
    private Weapon bareHands = new Weapon();

    public Equipment(Character character) {
        this.character = character;
        bareHands.parseDamage("1d4");//TODO: need to change this to reflect the class or race
        bareHands.setName("Unarmed");
        bareHands.setWeight(0.0);
        bareHands.setDescription("Tightening your hands into fists is one way of using Impovised Weapons.");
    }

    public void swapWeapons(Weapon newWeapon, boolean dropWeapon) {
        if(equiptedWeapon != null){//
            if(!dropWeapon)
                items.add(equiptedWeapon);

        }
        if(items.contains(newWeapon)){
            items.remove(newWeapon);
        }
        equiptedWeapon = newWeapon;
    }

    //Object will be Weapon
    public Weapon getEquiptWeapon() {
//        Iterator<Item> iter = items.iterator();
//        Item i;
//        while (iter.hasNext()) {
//            i = iter.next();
//            System.out.println("class of i is "+i.getClass().getName());
//            if (i instanceof Weapon) {
//                Weapon w = Weapon.class.cast(i);
//                if (i != null) {//if one-handed and in main-hand or two-handed
//                    if (false) {//if equipt
//                        return w;
//                    }
//                }
//            }
//        }
        if(equiptedWeapon==null)//if no weapon is equipt, look at class or race spec for what bare-hand damage is and return that
            return bareHands;
        return equiptedWeapon;
    }

    public <T extends Item> void addItem(T item) {
        items.add(item);
    }

    public double getWeight() {
        double rtv = 0.0;
        for (Item i : items) {
            rtv += i.getWeight();
        }
        return rtv;
    }

    {
        Item item = new Item();
        Weapon weapon = new Weapon();
        Armor armor = new Armor();
        Shield shield = new Shield();
//        Item<Weapon> iWeapon = new Item(new Weapon());
//        iWeapon.getT().getEnhancement();

        items.add(item);
        items.add(weapon);
        items.add(armor);
        items.add(shield);
        addItem(weapon);
//        items.add(iWeapon);
    }
}
